﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _06.MultiValueDictionary
{
    public class TestGenerator
    {
        static Random random;
        const int minCommands = 10000;
        const int maxCommands = 10000;
        const int minMember = -1000;
        const int maxMember = 1000;
        static string[] commands =
	{
		"Add", "Remove", "ContainsKey", "Count", "Clear", "this", "Foreach"
	};

        public static void CreateTest(string inputFileName)
        {
            string sequence = CreateSequence();
            PrintInput(@"..\..\Tests\" + inputFileName, sequence);
        }

        public static string CreateSequence()
        {
            random = new Random();
            StringBuilder test = new StringBuilder();
            int numberOfCommands = random.Next(minCommands, maxCommands);
            for (int i = 0; i < numberOfCommands; i++)
            {
                int command;
                if (i < numberOfCommands/3)
                {
                    command = random.Next(0, 1);
                }
                else
                {
                    command = random.Next(0, commands.Length);
                }
                switch (commands[command])
                {
                    case "Add":
                        {
                            test.AppendLine("Add | " + random.Next(minMember, maxMember) + "," + random.Next(minMember, maxMember));
                            break;
                        }
                    case "Remove":
                        {
                            test.AppendLine("Remove | " + random.Next(minMember, maxMember));
                            break;
                        }
                    case "ContainsKey":
                        {
                            test.AppendLine("ContainsKey | " + random.Next(minMember, maxMember));
                            break;
                        }

                    case "Count":
                        {
                            test.AppendLine("Count");
                            break;
                        }
                    case "Clear":
                        {
                           // test.AppendLine("Clear");
                            break;
                        }
                    case "this":
                        {

                            test.AppendLine("this | " + random.Next(minMember, maxMember));
                            break;
                        }
                    case "Foreach":
                        {
                            test.AppendLine("Foreach");
                            break;
                        }
                }

            }
            test.AppendLine("Foreach");
            test.AppendLine("End");


            return test.ToString();
        }

        private static void PrintInput(string fileName, string sequence)
        {
            StreamWriter writer = new StreamWriter(fileName);

            using (writer)
            {
                writer.WriteLine(sequence);
            }
        }
    }
}
